<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>检测项查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'检测项查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model.trim="queryInfo.factoryid" placeholder="请选择" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="开卡时间:" prop="containerstartdate">
          <el-date-picker v-model="queryInfo.containerstartdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:280px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="工序名称:">
          <el-input v-model.trim="queryInfo.workflowstepname" style="width: 100px;"></el-input>
        </el-form-item>

        <el-form-item label="状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择" clearable filterable style="width: 120px;">
            <el-option :key="'在制'" :label="'在制'" :value="0"></el-option>
            <el-option :key="'完工入库'" :label="'完工入库'" :value="1"></el-option>
            <el-option :key="'领料中'" :label="'领料中'" :value="-1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择" clearable filterable style="width: 140px;">
            <el-option v-for="p in productfamilyList" :key="p.productfamilyname" :label="p.productfamilyname"
              :value="p.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="入库时间:">
          <el-date-picker v-model="queryInfo.instoredate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="检验录入时间:">
          <el-date-picker v-model="queryInfo.checkdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <!-- <el-form-item label="热处理熔炉号:">
          <el-input v-model="queryInfo.specno" style="width: 100px;"></el-input>
        </el-form-item> -->

        <el-form-item label="查询类型:">
          <el-select v-model="queryInfo.seachtype" placeholder="请选择" style="width: 150px;">
            <el-option :key="'工艺属性'" :label="'工艺属性'" :value="'工艺属性'"></el-option>
            <el-option :key="'实测值基本数据'" :label="'实测值基本数据'" :value="'实测值基本数据'"></el-option>
            <el-option :key="'实测值基本属性'" :label="'实测值基本属性'" :value="'实测值基本属性'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="单元格合并显示:">
          <el-switch v-model="mergeCell" inactive-text="" active-text=""></el-switch>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border :span-method="handleSpanMethod">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="批次号" prop="containername" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="开卡时间" prop="originalstartdate" width="100" :formatter="splitDate" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="主制分厂" prop="factoryname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="入库时间" prop="instoredate" width="100" :formatter="splitDate" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="批次状态" prop="isinstore" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="工序名称" prop="workflowstepname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="工步名称" prop="stepinfoname" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="工步类型" prop="stepinfotype" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="检验序号" prop="bubblenumber" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="检验内容描述" prop="checkpointnotedis_b" width="100" show-overflow-tooltip>
          <template slot-scope="scope" v-if="scope.row.checkpointnotedis_b">
            <div v-html="scope.row.checkpointnotedis_b"></div>
          </template>
        </el-table-column>
        <el-table-column label="图纸规定" prop="drawingrequiredis_b" width="100" show-overflow-tooltip>
          <template slot-scope="scope" v-if="scope.row.drawingrequiredis_b">
            <div v-html="scope.row.drawingrequiredis_b"></div>
          </template>
        </el-table-column>
        <el-table-column label="实测值内容--工人" prop="workcheckpointresultnotedis_b" width="100" show-overflow-tooltip>
          <template slot-scope="scope" v-if="scope.row.workcheckpointresultnotedis_b">
            <div v-html="scope.row.workcheckpointresultnotedis_b"></div>
          </template>
        </el-table-column>
        <el-table-column label="录入人--工人" prop="worker" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="录入时间--工人" prop="workerdate" width="100" :formatter="splitDate" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="实测值内容--检验员" prop="checkpointresultnotedis_b" width="100" show-overflow-tooltip>
          <template slot-scope="scope" v-if="scope.row.checkpointresultnotedis_b">
            <div v-html="scope.row.checkpointresultnotedis_b"></div>
          </template>
        </el-table-column>
        <el-table-column label="录入人--检验员" prop="checker" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="录入时间--检验员" prop="checkdate" width="100" :formatter="splitDate" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="订单号" prop="mfgordername" width="100" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="机型" prop="familylistnames" width="100" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="零件图号" prop="productname" width="100" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="设计图版次" prop="part_revid" width="80" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="件号类型" prop="producttypename" width="80" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="工艺规程编号" prop="process_no" width="80" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="工艺规程版次" prop="ly2sequence" width="80" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="工艺路线" prop="workflowinfo" width="80" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="工艺类型" prop="workflowtype" width="80" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="工艺类型2" prop="workflowtype2" width="80" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="备注" prop="zbz" width="100" show-overflow-tooltip v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="废品单编号" prop="zfpdbh" width="100" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="质量问题处置单" prop="zlwtczd" width="100" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="不合格品审理单" prop="zbhgdh" width="100" show-overflow-tooltip
          v-if="queryInfo.seachtype === '工艺属性'">
        </el-table-column>
        <el-table-column label="工序检" prop="meopcheck" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="关键过程" prop="keycheck" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="质保单" prop="qualitycheck" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="安装单" prop="isinstall" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="拆卸单" prop="isdisassemble" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="通知单" prop="isnotice" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="返回单" prop="isreturn" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="综合性能表" prop="iscompp" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="是否SPC" prop="isspc" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="SPC检测类型" prop="spctype" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
        <el-table-column label="SPC判异规则" prop="spcrule" width="60" show-overflow-tooltip
          v-if="queryInfo.seachtype === '实测值基本属性'">
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getProductFamily, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { replaceDate, splitDate } from '../Scripts/hooks/format.js'
    import { getSpanArr } from '../Scripts/hooks/spanMethod.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        replaceDate,
        splitDate,
        queryInfo: {
          factoryid: '',
          mfgordername: '',
          productname: '',
          containername: '',
          productfamilyname: '',
          containerstartdate: '',
          workflowstepname: '',
          instoredate: '',
          status: '',
          seachtype: '工艺属性',
          checkdate: '',
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        factoryList: [], // 分厂列表
        productfamilyList: [],
        // 表单验证
        rules: {
          factoryid: [{ required: true, message: '主制分厂不能为空', trigger: 'change' }],
          // containerstartdate: [{ required: true, message: '开卡时间不能为空', trigger: 'change' }]
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        mergeCell: true,
        mergeColumns: [],
        mergeData: {}
      },
      methods: {
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback })
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/CheckPointResultReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
              if (data.length > 0) {
                this.mergeColumns = Object.keys(data[0]);
                for (const i of this.mergeColumns) {
                  this.mergeData[i] = getSpanArr(data, i);
                }
              }
            }
          })
        },
        // 导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空')
            } else {
              const config = {
                url: '../handler/report/CheckPointResultReport.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        // 合并单元格方法
        handleSpanMethod({ row, column, rowIndex, columnIndex }) {
          if (!this.mergeCell) { return; }
          if (this.mergeColumns.includes(column.property)) {
            const _row = this.mergeData[column.property][rowIndex];
            const _col = _row > 0 ? 1 : 0;
            return { rowspan: _row, colspan: _col };
          }
        }
      },
      async mounted() {
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.containerstartdate = [startOfThisMonth, endOfThisMonth];

        this.factoryList = await getFactory();
        this.productfamilyList = await getProductFamily();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.factoryid = factoryid;
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>